package com.dandandog.framework.common.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @Author: JohnnyLiu
 * @Date: 2021/11/17 11:26
 */
public class LocaleUtil {

    public static Locale getCurrLocale() {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            HttpServletResponse response = ((ServletRequestAttributes) requestAttributes).getResponse();
            if (response != null) {
                return response.getLocale();
            }
        }
        return Locale.getDefault();
    }
}
